      SUBROUTINE PK_CYLINDER(KFILDO,IPACK,ND5,IS3,NS3,IPKOPT,L3264B,
     1                       LOCN,IPOS,IER,*)
C
C        MARCH   2000   LAWRENCE   GSC/TDL   ORIGINAL CODING
C        JANUARY 2001   GLAHN      COMMENTS; IER = 303 CHANGED TO 304;
C                                  ADDED CHECK FOR SIZE OF IS3( )
C
C        PURPOSE
C            PACKS TEMPLATE 3.0, AN EQUIDISTANT CYLINDRICAL LATITUDE
C            LONGITUDE PROJECTION TEMPLATE, IN SECTION 3 OF A GRIB2
C            MESSAGE.  IT IS THE RESPONSIBILITY OF THE CALLING 
C            ROUTINE TO PACK THE FIRST 13 OCTETS IN SECTION 3.
C
C        DATA SET USE
C           KFILDO - UNIT NUMBER FOR OUTPUT (PRINT) FILE. (OUTPUT)
C
C        VARIABLES
C              KFILDO = UNIT NUMBER FOR OUTPUT (PRINT) FILE. (INPUT)
C            IPACK(J) = THE ARRAY THAT HOLDS THE ACTUAL PACKED MESSAGE
C                       (J=1,ND5). (INPUT/OUTPUT)
C                 ND5 = THE SIZE OF THE ARRAY IPACK( ). (INPUT)
C              IS3(J) = CONTAINS THE EQUIDISTANT CYLINDRICAL PROJECTION
C                       INFORMATION (IN ELEMENTS 15 THROUGH 72)
C                       THAT WILL BE PACKED INTO IPACK( ) (J=1,NS3).
C                       (INPUT/OUTPUT)
C                 NS3 = SIZE OF IS3( ). (INPUT) 
C              IPKOPT = PACKING INDICATOR:
C                       0 = ERROR, DON'T PACK
C                       1 = PACK IA( ), SIMPLE
C                       2 = PACK IA( ) AND IB( ), SIMPLE
C                       3 = PACK COMPLEX OR SPATIAL DIFFERENCING
C                       4 = PACK COMPLEX.
C                       (INPUT)
C              L3264B = THE INTEGER WORD LENGTH IN BITS OF THE MACHINE
C                       BEING USED. VALUES OF 32 AND 64 ARE
C                       ACCOMMODATED. (INPUT)
C                LOCN = THE WORD POSITION TO PLACE THE NEXT VALUE.
C                       (INPUT/OUTPUT)
C                IPOS = THE BIT POSITION IN LOCN TO START PLACING
C                       THE NEXT VALUE. (INPUT/OUTPUT)
C                 IER = RETURN STATUS CODE. (OUTPUT)
C                         0 = GOOD RETURN.
C                       1-4 = ERROR CODES GENERATED BY PKBG. SEE THE 
C                             DOCUMENTATION IN THE PKBG ROUTINE.
C                       302 = IS3( ) HAS NOT BEEN DIMENSIONED LARGE
C                             ENOUGH TO CONTAIN THE ENTIRE TEMPLATE. 
C                       304 = IS3(13) DOES NOT INDICATE POLAR
C                             STEREOGRAPHIC MAP PROJECTION; 
C                             INCORRECTLY CALLED SUBROUTINE. 
C                       310 = UNRECOGNIZED OR UNSUPPORTED SHAPE OF
C                             EARTH CODE IN IS3(15) RETURNED BY
C                             SUBROUTINE EARTH.
C                   * = ALTERNATE RETURN WHEN IER NE 0.
C
C             LOCAL VARIABLES
C               ISIGN = A FLAG INDICATING WHETHER A VALUE TO BE
C                       PACKED IS POSITIVE OR NEGATIVE. 
C                   N = L3264B = THE INTEGER WORD LENGTH IN BITS OF 
C                       THE MACHINE BEING USED. VALUES OF 32 AND
C                       64 ARE ACCOMMODATED. 
C             MINSIZE = THE SMALLEST ALLOWABLE DIMENSION FOR IS3( ).
C
C        NON SYSTEM SUBROUTINES CALLED
C           EARTH, PKBG
C
      PARAMETER(MINSIZE=72)
C
      DIMENSION IPACK(ND5),IS3(NS3)
C
      N=L3264B
      IER=0
C
C        CHECK TO MAKE SURE THAT THE USER WANTS TO PROCESS
C        A CYLINDRICAL EQUIDISTANT PROJECTION.  CHECK FOR NS3 GE 13
C        ASSURES A VALUE FOR IS3(13).
C
      IF(NS3.GE.13)THEN
C
         IF (IS3(13).NE.0)THEN
D           WRITE(KFILDO,10)IS3(13)
D10         FORMAT(/' MAP PROJECTION CODE ',I4,' INDICATED BY IS3(13)'/
D    1              ' IS NOT CYLINDRICAL EQUIDISTANT. PLEASE REFER TO'/
D    2              ' THE GRIB2 DOCUMENTATION TO DETERMINE THE'/
D    3              ' CORRECT MAP PROJECTION PACKER TO CALL.'/)
            IER=304
            GO TO 900
         ENDIF
C
      ELSE
         IER=302
         GO TO 900
      ENDIF
C
C        CHECK THE DIMENSIONS OF IS3( ).
C
      IF(NS3.LT.MINSIZE)THEN
         IER=302
         GO TO 900
      ENDIF
C
C        PACK THE SHAPE OF THE EARTH.
      CALL EARTH(KFILDO,IPACK,ND5,IS3,NS3,N,LOCN,IPOS,IER)
      IF(IER.NE.0)GOTO 900
C
C        PACK THE NUMBER POINTS ALONG A PARALLEL (Ni) AND THE
C        NUMBER OF POINTS ALONG ALONG A MERIDIAN (Nj).
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(31),32,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(35),32,N,IER,*900)
C
C        PACK THE BASIC ANGLE OF THE INITIAL PRODUCT DOMAIN.
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(39),32,N,IER,*900)
C
C        PACK THE SUBDIVISIONS OF THE BASIC ANGLE TO DEFINE EXTREME
C        LONGITUDES AND LATITUDES, AND DIRECTION INCREMENTS. THIS
C        VALUE MAY NEGATIVE. 
      ISIGN=0
      IF(IS3(43).LT.0) ISIGN=1
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ISIGN,1,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ABS(IS3(43)),31,N,IER,*900)
C
C        PACK THE LATITUDE & LONGITUDE OF THE FIRST GRID POINT
      ISIGN=0
      IF(IS3(47).LT.0) ISIGN=1
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ISIGN,1,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ABS(IS3(47)),
     1          31,N,IER,*900)
      ISIGN=0
      IF(IS3(51).LT.0) ISIGN=1
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ISIGN,1,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ABS(IS3(51)),
     1          31,N,IER,*900)
C
C        PACK THE RESOLUTION AND COMPONENT FLAGS.
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(55),8,N,IER,*900)
C
C        PACK THE LATITUDE OF THE LAST GRID POINT
      ISIGN=0
      IF(IS3(56).LT.0) ISIGN=1
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ISIGN,1,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ABS(IS3(56)),
     1          31,N,IER,*900)
C
C        PACK THE LONGITUDE OF THE LAST GRID POINT.
      ISIGN=0
      IF(IS3(60).LT.0) ISIGN=1
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ISIGN,1,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ABS(IS3(60)),
     1          31,N,IER,*900)
C
C        PACK THE I & J DIRECTION INCREMENTS (Di & Dj).
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(64),32,N,IER,*900)
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(68),32,N,IER,*900)
C
C        PACK THE SCANNING MODE. CHECK TO SEE IF THE DATA POINTS 
C        HAVE BEEN ORDERED BOUSTROPHEDONICALLY. IF SO, SET BIT 4
C        TO 1 IN THE SCANNING MODE OCTET.
C
CWDT  IF((IPKOPT.EQ.3).OR.(IPKOPT.EQ.4))THEN
CWDT     IS3(72)=IOR(IS3(72),16)
CWDT  ELSE
         IS3(72)=IAND(IS3(72),239)
CWDT  ENDIF
C
      CALL PKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS3(72),8,N,IER,*900)
C
C       ERROR RETURN SECTION
 900  IF(IER.NE.0)RETURN 1
C
      RETURN
      END
